﻿package mortal.game.view.copy.QuestionCopy.panel
{
    import Message.Public.*;
    import com.gengine.global.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.scene3D.map3D.util.*;
    import mortal.game.scene3D.player.entity.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.copy.QuestionCopy.data.*;
    import mortal.mvc.core.*;

    public class QuestionCopyChoicePanel extends BaseWindow
    {
        protected var _bg:GImageBitmap;
        protected var _titleDes:GTextFiled;
        protected var _timeCounter:BitmapNumberText;
        protected var _yourChoice:GTextFiled;
        protected var _leftBtn:GLoadingButton;
        protected var _leftAnswer:GTextFiled;
        protected var _rightBtn:GLoadingButton;
        protected var _rightAnswer:GTextFiled;
        protected var _wrongFlag:GBitmap;
        protected var _rightFlag:GBitmap;
        private var _isUILoad:Boolean = false;
        private var _info:Object;
        private var _leftTime:uint = 20;
        private var _qObj:Object = 0;
        private var _rightStr:String;
        private var _wrongStr:String;
        private static var _instance:QuestionCopyChoicePanel;

        public function QuestionCopyChoicePanel()
        {
            this._rightStr = "" + Language.getString(71523);
            this._wrongStr = "" + Language.getString(71522);
            this.layer = LayerManager.uiLayer;
            this.setSize(667, 250);
            this.title = "" + Language.getString(70950);
            this._tweenable = false;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            LoaderHelp.addResCallBack(ResFileConst.questionCopy, this.onShowWin);
            return;
        }// end function

        private function onShowWin() : void
        {
            this._isUILoad = true;
            this._bg = UIFactory.gImageBitmap(ImagesConst.QuestionCopyChoiceBg, 7, 35, this);
            this._titleDes = UIFactory.gTextField("", 271, 55, 500, 60, this, GlobalStyle.textFormatPutong.setColor(16777215).setSize(15).setBold(true));
            this._timeCounter = UIFactory.bitmapNumberText(332, 264, "ReliveNum.png", 41, 43, -6, this, 9, 1);
            this._timeCounter.text = "20";
            this._yourChoice = UIFactory.gTextField("" + Language.getString(70951), 172, 176, 100, 25, this, GlobalStyle.textFormatHong.setSize(13).setBold(true));
            this._leftBtn = UIFactory.gLoadingButton(ImagesConst.LineOffBtn_upSkin, 137, 135, 140, 43, this);
            this._leftBtn.label = "";
            this._leftAnswer = UIFactory.gTextField("" + Language.getString(70952), 135, 145, 140, 20, this, GlobalStyle.textFormatPutong.setColor(16777215).setSize(14).center().setBold(true));
            this._rightBtn = UIFactory.gLoadingButton(ImagesConst.LineOffBtn_upSkin, 402, 135, 140, 43, this);
            this._rightBtn.label = "";
            this._rightAnswer = UIFactory.gTextField("" + Language.getString(70953), 424, 145, 100, 20, this, GlobalStyle.textFormatPutong.setColor(16777215).setSize(14).center().setBold(true));
            this._wrongFlag = UIFactory.gBitmap(ImagesConst.QuestionCopyChoiceWrong, 48, 130, this);
            this._rightFlag = UIFactory.gBitmap(ImagesConst.QuestionCopyChoiceRight, 576, 125, this);
            var _loc_1:Boolean = false;
            this._yourChoice.visible = false;
            var _loc_1:* = _loc_1;
            this._rightFlag.visible = _loc_1;
            this._wrongFlag.visible = _loc_1;
            var _loc_1:Boolean = false;
            this._rightAnswer.mouseEnabled = false;
            this._leftAnswer.mouseEnabled = _loc_1;
            this._leftBtn.configEventListener(MouseEvent.CLICK, this.onChoiceHd);
            this._rightBtn.configEventListener(MouseEvent.CLICK, this.onChoiceHd);
            this.closeBtn.visible = false;
            this.btnEnable(false);
            if (this._info != null)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.CopyQuestioReqSynTime));
                this.beginShowTitle(this._info);
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._bg = null;
            this._titleDes = null;
            this._timeCounter = null;
            this._yourChoice = null;
            this._leftBtn = null;
            this._leftAnswer = null;
            this._rightBtn = null;
            this._rightAnswer = null;
            this._wrongFlag = null;
            this._rightFlag = null;
            this._info = null;
            this._isUILoad = false;
            return;
        }// end function

        public function beginShowTitle(param1:Object) : void
        {
            if (param1 == null)
            {
                return;
            }
            this._info = param1;
            if (this._isUILoad == false)
            {
                return;
            }
            this._qObj = QuestionCopyDataUtil.getTitleById(param1.questionId, param1.shuffleOption);
            this._leftTime = param1.surplusSeconds;
            this.setTitle(param1.questionIndex);
            this.showTime();
            this.showAnswer(param1);
            this.updateYouChoice();
            return;
        }// end function

        private function onEnterTime(param1:Object) : void
        {
            this.showTime();
            return;
        }// end function

        private function setTitle(param1:int) : void
        {
            this._titleDes.text = param1 + "、 " + this._qObj.question;
            this._leftAnswer.text = "" + this._qObj.option1;
            this._rightAnswer.text = "" + this._qObj.option2;
            return;
        }// end function

        private function setBtn(param1:Object) : void
        {
            if (ECopyStatus._ECopyStatusShowAnswer == param1.status)
            {
                this.btnEnable(true);
            }
            else
            {
                this.btnEnable(false);
            }
            return;
        }// end function

        public function showTime() : void
        {
            if (this._isUILoad == false)
            {
                return;
            }
            var _loc_1:* = Cache.instance.question.getShowTime();
            if (_loc_1 > 0)
            {
            }
            this._timeCounter.text = "" + _loc_1;
            return;
        }// end function

        private function showAnswer(param1:Object) : void
        {
            if (ECopyStatus._ECopyStatusShowAnswer == param1.status)
            {
                this._rightFlag.visible = false;
                this._wrongFlag.visible = false;
                if (this._qObj.answer == 1)
                {
                    if (this._yourChoice.x < 220)
                    {
                        this._rightFlag.x = 40;
                        this._rightFlag.visible = true;
                        Dispatcher.dispatchEvent(new DataEvent(EventName.CopyQuestioShowRightEffect));
                        MsgManager.showTaskTarget(this._rightStr);
                    }
                    else
                    {
                        this._wrongFlag.x = 570;
                        this._wrongFlag.visible = true;
                        MsgManager.showTaskTarget(this._wrongStr);
                    }
                }
                else if (this._yourChoice.x > 220)
                {
                    this._rightFlag.x = 577;
                    this._rightFlag.visible = true;
                    Dispatcher.dispatchEvent(new DataEvent(EventName.CopyQuestioShowRightEffect));
                    MsgManager.showTaskTarget(this._rightStr);
                }
                else
                {
                    this._wrongFlag.x = 48;
                    this._wrongFlag.visible = true;
                    MsgManager.showTaskTarget(this._wrongStr);
                }
            }
            else
            {
                this._rightFlag.visible = false;
                this._wrongFlag.visible = false;
            }
            return;
        }// end function

        public function updateYouChoice() : void
        {
            if (this._isUILoad == false || this._info == null)
            {
                return;
            }
            if (ECopyStatus._ECopyStatusShowAnswer == this._info.status)
            {
                return;
            }
            var _loc_1:* = GameMapUtil.getPixelPointValue(RolePlayer.instance.x2d, RolePlayer.instance.y2d);
            this._yourChoice.visible = true;
            if (_loc_1 == 28)
            {
                this._yourChoice.x = 172;
            }
            else
            {
                this._yourChoice.x = 441;
            }
            return;
        }// end function

        private function btnEnable(param1:Boolean) : void
        {
            return;
        }// end function

        private function onChoiceHd(event:MouseEvent) : void
        {
            var _loc_2:int = 1;
            if (this._rightBtn == event.currentTarget)
            {
                _loc_2 = 2;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.CopyQuestionMakeChioce, _loc_2));
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            super.show(param1, param2);
            this.stageResize();
            return;
        }// end function

        override public function stageResize() : void
        {
            super.stageResize();
            x = Global.stage.stageWidth - this.width >> 1;
            y = 200;
            return;
        }// end function

        public static function get instance() : QuestionCopyChoicePanel
        {
            if (_instance == null)
            {
                _instance = new QuestionCopyChoicePanel;
            }
            return _instance;
        }// end function

    }
}
